package com.wuze.cloud.context;

import com.wuze.cloud.enums.SysGlobalExceptionEnum;
import com.wuze.cloud.exception.SysGlobalException;
import com.wuze.cloud.pojo.SysUserDO;

import java.util.Objects;

/**
 * @author: wuze
 * @description:
 * @date: 2023/02/17
 */
public class UserContext {

    private static ThreadLocal<SysUserDO> context = new ThreadLocal<>();

    public static SysUserDO getUser(){
        SysUserDO user = context.get();
        if(Objects.isNull(user)){
            throw new SysGlobalException(SysGlobalExceptionEnum.USER_EMPTY.getMsg());
        }
        return user;
    }

    public static void setUser(SysUserDO user){
        context.set(user);
    }
}
